class Solution(object):
    def isStrobogrammatic(self, num):
        """
        :type num: str
        :rtype: bool
        """
        d = {'0': '0', '1': '1', '6': '9', '8': '8', '9':'6'}
        r = len(num) - 1
        l = 0
        while l < r:
            if num[l] in d and num[r] == d[num[l]]:
                l += 1
                r -= 1
                continue
            else:
                return False
        if l == r:
            if num[l] not in ['0', '1', '8']:
                return False
        return True


data = Solution()
num = '18'
print(data.isStrobogrammatic(num))